package net.lzzy.tapDemo;
import net.lzzy.pojo.Recode;
import org.apache.spark.SparkConf;
import org.apache.spark.api.java.JavaPairRDD;
import org.apache.spark.api.java.JavaRDD;
import org.apache.spark.api.java.JavaSparkContext;
import org.apache.spark.api.java.function.Function;
import org.apache.spark.api.java.function.PairFunction;
import scala.Tuple2;

import java.util.List;

public class IndexRecordsTest3 {
    public static void main(String[] args) {
        SparkConf conf = new SparkConf().setAppName("IndexRecordsTest").setMaster("local");
        JavaSparkContext jsc = new JavaSparkContext(conf);
        JavaRDD<String> javaRDD = jsc.textFile("src\\records.txt");
        JavaRDD<String> javaRDD1 = jsc.textFile("src\\recordsCityB.txt");

        JavaRDD<Recode> map = javaRDD.map( v1 -> {
                String[] split = v1.split("\t");
                return new Recode(split[2], split[3]);
            });

        JavaRDD<Recode> map2 = javaRDD1.map( v1 -> {
            String[] split = v1.split("\t");
            return new Recode(split[2], split[3]);
        });

        List<Recode> collect = map.intersection(map2).filter(v1 ->
                "AK0803".equals(v1.getCarNo())
        ).collect();

        for (Recode recode : collect) {
            System.out.println(recode.getTypeNo());
        }


    }
}
